<link rel='stylesheet' href='<?php echo base_url();?>css/calendar.css' title='calendar'>

<script language="javascript" src="<?php echo base_url();?>js/calendar.js"></script>

<script language="javascript">

$(document).ready(function(){
	$('.date-pick').datePicker({startDate:'1996.01.01'});
    $("#mod_id").change(function(){
        var mod_id = $(this).val();
        $.ajax({
	    	   type: "POST",
	    	   url:"<?php echo  base_url();?>model/get_category",
	    	   data: "mod_id="+mod_id,
	    	   success: function(msg){
	    		   $("#category_id").html("");
		    	   $("#category_id").html(msg);
	    	   }
	    	});
        if(mod_id==""){
      	   var str="<font color='red'>请选择型号！</font>";
             $("#mod_id_notice").html('');
             $("#mod_id_notice").html(str);
             return false;
         }else{
      	   $("#mod_id_notice").html('');
         }
    })

    
    $("#category_id").change(function(){
       var mod_id=$(this).val();
       if(mod_id==""){
    	   var str="<font color='red'>请选择类别！</font>";
           $("#category_id_notice").html('');
           $("#category_id_notice").html(str);
           return false;
       }else{
    	   $("#category_id_notice").html('');
       }
	})
	
	
    $("#submit").click(function(){
       var mod_id=$("#mod_id").val();
       var category_id=$("#category_id").val();   
       var name=$("#name").val();
       var count=$("#count").val();
       if(mod_id==""){
    	   var str="<font color='red'>请选择型号！</font>";
           $("#mod_id_notice").html('');
           $("#mod_id_notice").html(str);
           return false;
       }
       if(category_id==""){
    	   var str="<font color='red'>请选择类别！</font>";
           $("#category_id_notice").html('');
           $("#category_id_notice").html(str);
           return false;
       } 
       if(name==""){
    	   var str="<font color='red'>版本名称不能空！</font>";
           $("#name_notice").html('');
           $("#name_notice").html(str);
           return false;
       } 
          
    })	
    $("#name").change(function(){
          var name = $(this).val();
          var ed = $("#ed").val();
          var category_id = $("#category_id").val();
          if(ed=="0"){
	          $.ajax({
		    	   type: "POST",
		    	   url: "<?php echo base_url();?>model/auth",
		    	   data: "name="+name+"&category_id="+category_id+"&type=version",
		    	   success: function(msg){
			    	   if(msg>=1){
	                       $("#submit").attr('disabled',true);
	                       $("#name_notice").html('已经有此版本,提交不能成功');
				       }else{
				    	   $("#submit").attr('disabled',false);
				    	   $("#name_notice").html('');
	  			      }
		    	   }
		    	}); 
          }
      })
})
function isDate(str)
{
	 var reg=/^((?:19|20)\d\d).(0[1-9]|1[012]).(0[1-9]|[12][0-9]|3[01])$/;
	 var r = str.match(reg);
	 return r;
}

function date_check(){
     var time = document.getElementById('name').value;
     var tr = isDate(time);
     if(!tr){
         document.getElementById("submit").disabled=true; 
         document.getElementById("name_notice").innerHTML="<font color='red'>版本名称格式：2000.10.10</font>";  
     }else{
    	 document.getElementById("submit").disabled=false;   
         }
	
}
</script>
		<div id="center-column">
			<div class="top-bar">
				<a href="<?php echo  base_url();?>model/version_add" class="button">新增</a>
				<h1>Contents</h1>
				<div class="breadcrumbs"><a href="#">首页</a> /<?php echo anchor('model/version_add','添加型号资料');?></div>
			</div>
			
		  <div class="table add_table">
				<input type="hidden"  id="ed" <?php if(isset($id)){ ?>value="1" <?php }else{?>value="0"<?php } ?>/> 
				
				<table class="listing form" cellpadding="0" cellspacing="0">
				  <?php if(isset($id)){echo form_open('model/version_edit/'.$id);}else{echo form_open('model/version_add');}?>
					<tr>
						<th  colspan="2"  align="center"><?php if(isset($id)){?>编辑资料版本<?php }else{?>新增资料版本<?php }?></th>
					</tr>
					<tr>
						<td class="first" width="172"><strong>型号：</strong></td>
						<td class="last"><select name="mod_id" id="mod_id">
						                   <option value="">请选择型号</option>
						                   <?php foreach($mod as $k=>$val):?>
						                     <option value="<?php echo $val->mod_id;?>" <?php if(isset($id)){ if($val->mod_id==$version->mod_id){?>selected<?php } }?>><?php echo $val->name;?></option>
						                   <?php endforeach;?>
						                 </select><span id="mod_id_notice"></span></td>
					</tr>
					<tr>
						<td class="first" width="172"><strong>资料种类：</strong></td>
						<td class="last"><select name="category_id" id="category_id">
					                         	<option value="">请选择资料种类</option>
						                  <?php if(isset($id)){?>
						                    	<option value="">请选择资料种类</option>
						                   <?php foreach($category as $k=>$val):?>
						                     <option value="<?php echo $val->category_id;?>" <?php if(isset($id)){ if($val->category_id==$version->category_id){?>selected<?php } }?>><?php echo $val->name;?></option>
						                   <?php  endforeach;}?>
						                 </select><span id="category_id_notice"></span></td>
					</tr>

					<tr class="bg">
						<td class="first""><strong>版本名称：</strong></td>
						<td class="last"><input name='name' onchange="date_check()" id="name" class='date-pick' value="<?php if(isset($id)){echo $version->name;}?>" ><span id="name_notice" style="color:#FF0000;padding-left:5px;"></span></td>
					</tr>
					<tr class="bg">
						<td class="first"><strong>备注：</strong></td>
						<td class="last"><textarea name="des" cols="80" rows="5"><?php if(isset($id)){echo $version->des;}?></textarea></td>
					</tr>
					<tr>
						<td colspan="2" style="text-align:center;"><input type="submit" value="提交" class="button" id="submit"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="返回" class="button" onclick="location.href='<?php echo site_url()?>model/version'" /></td>			
					</tr>
				</form>	
				</table>
	        <p>&nbsp;</p>
		  </div>
		</div>
	</div>
	<div id="footer"></div>
</div>



</body>
</html>
